#
# Manual makefile of ERUTA project relies on availability of the standard c99 compiler
# Hey, it's long past 2000. :)
#


# Environment 

SDL_LIBS=`sdl-config --libs`


CC=g++
CCOPTS=-I ./ext/lua
DBGOPTS=-g -pg
LDOPTS=-L/usr/lib -lSDL_image -lSDL_ttf -lSDL  -lpthread
MKDIR=mkdir
CP=cp
CCADMIN=CCadmin
RANLIB=ranlib
CD=cd
LD=ld
DEBUGGER=gdb


# build

LUALIBA=ext/lua/liblua.a
DEBUG_EXE=dist/eruta_debug
SOURCES:=$(wildcard srcpp/*.cpp)
HEADERS:=$(wildcard srcpp/*.h)
OBJECTS:=$(patsubst %.cpp,%.o,$(SOURCES))
# Standard .makefile
# 1. Genererate a variable with the name of all object files.
# OBJECTS = $(SOURCES:.cpp=.o)

# dependencies
MAKEDEP=g++ -MM $(CCOPTS)



$(DEBUG_EXE): $(LUALIBA) $(OBJECTS) 
	@echo $(OBJECTS)
	$(CC) $(DBGOPTS) $(CCOPTS) $(OBJECTS) $(LUALIBA) $(LDOPTS) -o $(DEBUG_EXE)

# $(OBJECTS):
#	$(CC) $(DBGOPTS) $(CCOPTS) -c  $*.cpp -o $@

%.o : %.cpp
	$(CC) $(DBGOPTS) $(CCOPTS) -c  $< -o $@

run: $(DEBUG_EXE)
	$(DEBUG_EXE)
	
debug: $(DEBUG_EXE)
	$(DEBUGGER) $(DEBUG_EXE)
	
$(LUALIBA): ext/lua/Makefile
	$(MAKE) -C ext/lua/

dep: .dependencies

# Auto-dependency generation
# Makefile	: .dependencies

include .dependencies

clean:
	$(RM) $(DEBUG_EXE) $(OBJECTS) .dependencies
	
veryclean: clean
	$(RM) ext/lua/liblua.a

test: 
	echo $(SDL_LIBS)


# Generate the dependencies
.dependencies	: $(HEADERS) $(SOURCES)
	$(MAKEDEP) $(SOURCES) > .dependencies


	
.PHONY: clean veryclean run debug dep test compile debug_objects
.PRECIOUS: $(OBJECTS)

